package com.where_to_play_search;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;

public class GetlistFromSearch {
	public static List<Map<String, String>> getlistfromsearch(String str) {
		List<Map<String, String>> listtotal = new ArrayList<Map<String, String>>();
		JSONObject object;
		try {
			object = new JSONObject(str);
			JSONArray array = object.getJSONArray("findHotelInfos");
			Map<String, String> map = null;
			for (int i = 0; i < array.length(); i++) {
				map = new HashMap<String, String>();
				JSONObject obj1 = array.getJSONObject(i);
				map.put("description", obj1.getString("description"));
				map.put("favoriteNum", obj1.getString("favoriteNum"));
				map.put("findId", obj1.getString("findId"));
				map.put("h5Url", obj1.getString("h5Url"));
				map.put("imgUrl", obj1.getString("imgUrl"));
				map.put("isMyFavorites", obj1.getString("isMyFavorites"));

				JSONArray array1 = obj1.getJSONArray("labels");
				String str_labels = "";
				String str_label = "·";
				for (int j = 0; j < array1.length(); j++) {
					str_labels = str_labels + str_label + array1.getString(j);
				}
				map.put("labels", str_labels);

				map.put("title", obj1.getString("title"));
				map.put("shareUrl", obj1.getString("shareUrl"));
				listtotal.add(map);
			}
			return listtotal;
		} catch (JSONException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		return null;
	}
}
